home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Aminet
/
comm
/
tcp
/
FtpDaemon.lha
/
amimsg
/
amimsg.c
< prev
Wrap
C/C++ Source or Header
|
1993-10-29
|
2KB
|
93 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <libraries/multiuser.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/multiuser.h>
struct muBase *muBase;
long gethostname(char *,long len);
char CommandTemplate[]="MSG/A,TO/K,NAME=FROM/K";
LONG CommandResults[]={NULL,(LONG)"localhost",(LONG)"root"};
char hostname[30];
char Buffer[512];
void main(void)
{
struct RDArgs *CommandRDArgs;
struct sockaddr_in server;
struct servent *sp;
struct hostent *hp;
char UserName[muUSERIDSIZE]="";
long s;
if((CommandRDArgs=ReadArgs(CommandTemplate,CommandResults,NULL)))
{
muBase=(struct muBase *)OpenLibrary(MULTIUSERNAME,MULTIUSERVERSION);
if(muBase)
{
struct muUserInfo *UserInfo;
if(UserInfo=muAllocUserInfo())
{
UserInfo->uid=(muGetTaskOwner(NULL)&muMASK_UID)>>16;
if(muGetUserInfo(UserInfo,muKeyType_uid))
{
strcpy(UserName,UserInfo->UserID);
CommandResults[2]=(LONG)UserName;
}
muFreeUserInfo(UserInfo);
}
CloseLibrary((struct Library *)muBase);
}
gethostname(hostname,sizeof(hostname));
sp=getservbyname("amimsg","tcp");
if(sp==NULL)
fprintf(stderr,"amimsg: tcp/amimsg: unknown service\n");
else
{
hp=gethostbyname((char *)CommandResults[1]);
if(hp==NULL)
fprintf(stderr,"amimsg: %s unknown host\n",CommandResults[1]);
else
{
bzero((char *)&server,sizeof(server));
server.sin_port=sp->s_port;
bcopy(hp->h_addr,(char *)&server.sin_addr,hp->h_length);
server.sin_family=hp->h_addrtype;
s=socket(AF_INET,SOCK_STREAM,0);
if(s<0)
perror("amimsg: socket");
else
{
if(connect(s,(struct sockaddr *)&server,sizeof(server))<0)
perror("amimsg: connect");
else
{
sprintf(Buffer,
"HOST %s\n"
"USER %s\n"
"MSG %s\n",
hostname,
CommandResults[2],
CommandResults[0]
);
send(s,Buffer,strlen(Buffer),0);
}
}
}
}
FreeArgs(CommandRDArgs);
}
else fprintf(stderr,"bad args.\n");
}